import IntegrationTable, {
	IntegrationTableProps,
} from "@/components/IntegrationTable";
import React, { useEffect } from "react";
import { Image, Radio } from "antd";
import type { ProColumns } from "@ant-design/pro-table";
// @page 商家
const Business: React.FC<any> = () => {
	// 组件是否已经卸载
	let isUnMounted = false;
	const propertyType = [
		{ label: "通过", value: 1 },
		{ label: "驳回", value: 2 },
	];

	// 表格项
	const columns: ProColumns[] = [
		{
			title: "id",
			dataIndex: "id",
			search: false,
		},
		{
			title: "用户昵称",
			dataIndex: "userName",
			search: false,
		},
		{
			title: "手机号",
			dataIndex: "phone",
			search: false,
		},
		{
			title: "拒绝原因",
			dataIndex: "reason",
			search: false,
		},
		{
			title: "状态",
			dataIndex: "status",
			valueEnum: {
				0: "待审核",
				1: "审核通过",
				2: "审核失败",
			},
		},
		{
			title: "创建时间",
			dataIndex: "applyTime",
			search: false,
		},
	];
	// 表单项
	const getFormItems = (vm: any, isEdit?: boolean): any[] => {
		const { coupon } = vm.state;
		return [
			{
				type: "custom",
				label: "状态",
				name: "auditStatus",
				required: true,
				render: (form: any, record: any) => {
					return (
						<Radio.Group
							options={propertyType}
							defaultValue={record.auditStatus}
							onChange={({ target }) => {
								form?.setFieldsValue({ auditStatus: target?.value });
								vm.setState({ classifyId: target?.value });
							}}
						></Radio.Group>
					);
				},
			},
			...(vm.state.classifyId == 2
				? [
						{
							type: "textarea",
							label: "拒绝原因",
							name: "reason",
							required: true,
						},
				  ]
				: []),
		];
	};
	// 一体化表格props
	const tablePorps: IntegrationTableProps = {
		rowKey: "id",
		scroll: { x: 1000 },
		columns,
		listProps: {
			url: "/recycler/list",
			method: "GET",
			requestType: "params",
			paramsHandle: (params: any) => {
				return {
					...params,
				};
			},
		},
		updateProps: {
			url: "/recycler/audit",
			method: "POST",
			btnText: (record: any) => {
				if (record) {
					return record.status === 0 ? "审核" : "";
				}
				return "审核";
			},
			modalProps: {
				formItemsHandle: (_: any, vm: any) => {
					return getFormItems(vm, true);
				},
			},
		},
	};

	// 初始化加载数据
	useEffect(() => {
		return () => {
			isUnMounted = true;
		};
	}, []);

	return <IntegrationTable {...tablePorps} />;
};

export default Business;
